package com.zhuss.team.processor;

import com.zhuss.bean.bo.team.invest.CreateInvestQuestionBo;
import com.zhuss.common.AbstractProcessor;
import com.zhuss.common.Processor;
import com.zhuss.core.db.dao.ext.RolePermissionDao;
import com.zhuss.db.entity.OpLog;
import com.zhuss.enums.LogActionEnum;
import com.zhuss.enums.MoudleEnum;
import com.zhuss.exception.WpsException;
import com.zhuss.team.db.dao.ext.InvestQuestionDao;
import com.zhuss.team.db.entity.InvestQuestion;
import com.zhuss.util.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Author: zhushanshuo
 * @Date: 2020/3/30 14:49
 */
@Component("investQuestionCreate")
public class InvestQuestionCreate extends AbstractProcessor<Object, CreateInvestQuestionBo> implements Processor<Object, CreateInvestQuestionBo> {

    @Autowired
    private InvestQuestionDao investQuestionDao;

    @Override
    public Object process(CreateInvestQuestionBo bo) throws WpsException {
        InvestQuestion iq = new InvestQuestion();
        iq.setInvestId(bo.getInvestId());
        iq.setQuestionId(bo.getQuestionId());

        iq.setCreatorId(bo.getConcurrentUserId());
        iq.setCreator(bo.getConcurrentUserName());
        iq.setCreateTime(new Date());
        investQuestionDao.create(iq);
        bo.setTargetId(iq.getInvestQuestionId());
        return null;
    }

    @Override
    public Object log(CreateInvestQuestionBo param) throws WpsException {
        OpLog record = new OpLog();
        record.setMoudle(MoudleEnum.协同发布.key());
        record.setAction(LogActionEnum.问卷问题关系建立.key());
        record.setTargetId(param.getTargetId());
        record.setTargetName("");
        record.setContent("参数: " + JsonUtil.toJson(param));
        record.setReason(param.getExceptionReason());

        record.setCreatorId(param.getConcurrentUserId());
        record.setCreator(param.getConcurrentUserName());
        record.setCreateTime(new Date());
        log(record);
        return null;
    }

    @Override
    public void check(CreateInvestQuestionBo createInvestQuestionBo) throws WpsException {

    }
}
